/**
 * Copyright 2011 Joe Choi, All rights reserved.
 */
package tec.encode.han.conv;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import tec.encode.ConvertUtil;
import tec.encode.FileUtil;
import tec.encode.FormatUtil;
import tec.encode.PrintUtil;
import tec.encode.han.CodeUtil;
import tec.encode.han.conv.JChineseConvertor;

/**
 * @author Joe Choi
 */
public class TSComparator {
	public static void main(String[] args) throws IOException {
		new TSComparator().comparePowerT2S();
	}
	
	public TSComparator() {}
	
	public void comparePowerT2S() throws IOException {
		List<Character> sc = CodeUtil.loadSimplified();
		JChineseConvertor tsconv = JChineseConvertor.getInstance();
		Map<Character, Character> pts = loadPowerT2S();
		String output = "";
		for(char c : sc) {
			if(pts.get(c) != null) {
				if(! pts.get(c).equals(tsconv.s2t(c))) {
					output += FormatUtil.formatByte(ConvertUtil.toByte(c)) + "-" + 
								c + ": " +
								pts.get(c) + ", " +
								tsconv.s2t(c) + PrintUtil.lineBreak();
				}
			}
		}
		FileUtil.save(output, "out/cmpPowerT2S.txt", "UTF-8");
	}
	
	public Map<Character, Character> loadPowerT2S() throws IOException {
		List<String> content = FileUtil.readTxtFile("cfg/TS.ini", "UTF-8");
		Map<Character, Character> pts = new HashMap<Character, Character>();
		for(String line : content) {
			String[] values = line.split("\\s+");
			pts.put(values[0].charAt(0), values[1].charAt(0));
		}
		
		return(pts);
	}
}
